<?php
require_once 'lib/config.php';
require_once 'lib/functions.php';

$user = isset($_SESSION['username'])?$_SESSION['username']:false;
if (!$user) {
    msg('','login.php');
}

if ($_GET) {
    $id = isset($_GET['id'])?$_GET['id']:'';
    if (intval($id)>0) {
        if ($db->query("DELETE FROM `guestbook` WHERE `id` = '$id'")) {
            msg('删除成功','index.php');
        } else {
			msg('系统错误');
        }
    }
}

$num = $db->query('select count(*) as total from guestbook')->fetch();
$num = $num['total'];

$page = isset($_GET['page'])?intval($_GET['page']):1;
if ($page<=0) {
    $page =1;
}
$pagesize = 10;
$start = $pagesize*($page-1);

$list = $db->query("select * from guestbook order by id desc limit $start,$pagesize")->fetchAll(PDO::FETCH_ASSOC);
foreach($list as $k=>$v){
    $list[$k]['t'] = date('Y-m-d H:i:s',$v['t']);
    $list[$k]['nickname'] = $v['nickname'];
    $list[$k]['content'] = $v['content'];
    $list[$k]['reply'] = $v['reply']<>''?$v['reply']:'暂未回复';
}
$page = page($pagesize, $num, $page, 'admin.php?');

require_once 'template/'.TPL.'/'.basename(__FILE__);
